// pages/real_name/real_name.js
var app = getApp();
const db = wx.cloud.database();
let zlList = {}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    content: '你确定要成为一名光荣的小编吗？',
  },
  _loadzlList() {
    wx.showLoading({
      title: '加载中',
    })
    wx.cloud.callFunction({
      name: 'zl',
      data: {
        $url: 'getListByOpenid',
        start: 0,
        count: 10,
      }
    }).then((res) => {
      this.setData({
        zlList: res.result

      })
      wx.hideLoading()
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this._loadzlList()
  },
  qiye: function (e) {


    if (this.data.confirm) {
      db.collection('shengji').add({
        data: {
          _id: this.data.zlList[0]._id,
          nickName: this.data.zlList[0].nickName,
          avatarUrl: this.data.zlList[0].avatarUrl,
          gender: this.data.zlList[0].gender,
          nl: this.data.zlList[0].nl,
          province: this.data.zlList[0].province,
          QQ: this.data.zlList[0].QQ,
          yx: this.data.zlList[0].yx,
          dh: this.data.zlList[0].dh,
          nl: this.data.zlList[0].nl,
          xb: this.data.zlList[0].xb,
          createTime: this.data.zlList[0].createTime,
          nengliang: this.data.zlList[0].nengliang,

        }
      }).then(res => {
        wx.showToast({
          icon: 'none',
          title: '申请完成，请等待认证',
        })
      }).catch((err) => {
        wx.hideLoading()
        wx.showToast({
          icon: 'none',
          title: '请勿重复申请',
        })
      })
    } else {
      wx.showToast({
        title: '请确认认证协议',
      })
    }



  },
  content: function () {
    var that = this;
    wx.showModal({
      title: '小编认证协议',
      content: that.data.content,
      success: function (res) {
        if (res.confirm) {
          that.setData({
            confirm: res.confirm
          })
          console.log('用户点击确定')
        } else if (res.cancel) {
          that.setData({
            confirm: res.confirm
          })
          console.log('用户点击取消')
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})